import React from 'react'
import { getPostBySlug } from '@/db/queries'
import { auth } from '@/lib/auth'
import { headers } from 'next/headers'
import PostContent from '@/components/post/post-content'

export default async function PostDetailPage({ params }: { params: Promise<{ slug: string }> }) {
    const { slug } = await params

    const postDetail = await getPostBySlug(slug)

    const session = await auth.api.getSession({
        headers: await headers()
    })

    if (!postDetail) {
        return (
            <div>Post not found</div>
        )
    }

    const isAuthor = session?.user?.id === postDetail.authorId

    return <main className='py-10'>
        <div className='max-w-4xl mx-auto'>
            <PostContent post={postDetail} isAuthor={isAuthor} />
        </div>
    </main>
}
